package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardFile;
import com.jhgsys.internal.incentive.service.IIncentiveRewardFileService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励附件 Controller
 *
 * @author wanghjw
 * @date 2024-09-03 14:08:33
 */
@Slf4j
@Validated
@Controller
public class IncentiveRewardFileController extends BaseController {

    @Autowired
    private IIncentiveRewardFileService incentiveRewardFileService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardFile")
    @RequiresPermissions("incentiveRewardFile:view")
    public String incentiveRewardFileIndex(){
        return FebsUtil.view("incentive/incentiveRewardFile/incentiveRewardFileList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardFile/add")
    @RequiresPermissions("incentiveRewardFile:add")
    public String incentiveRewardFileAdd(){
        return FebsUtil.view("incentive/incentiveRewardFile/incentiveRewardFileEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardFile/update/{id}")
    @RequiresPermissions("incentiveRewardFile:edit")
    public String incentiveRewardFileUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveRewardFile", incentiveRewardFileService.findIncentiveRewardFileById(id));
        return FebsUtil.view("incentive/incentiveRewardFile/incentiveRewardFileEdit");
    }

    /**
     * 查询（所有）
     * @author wanghjw
     * @date 2024-09-03 14:08:33
     */
    @GetMapping("incentiveRewardFile")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:view")
    public FebsResponse getAllIncentiveRewardFiles(IncentiveRewardFile incentiveRewardFile) {
        return new FebsResponse().success().data(incentiveRewardFileService.findIncentiveRewardFileList(incentiveRewardFile));
    }

    /**
     * 查询（分页）
     * @author wanghjw
     * @date 2024-09-03 14:08:33
     */
    @GetMapping("incentiveRewardFile/list")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:view")
    public FebsResponse incentiveRewardFileList(QueryRequest request, IncentiveRewardFile incentiveRewardFile) {
        Map<String, Object> dataTable = getDataTable(this.incentiveRewardFileService.findIncentiveRewardFilePage(request, incentiveRewardFile));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveRewardFile
     * @author wanghjw
     * @date 2024-09-03 14:08:33
     */
    @Log("新增IncentiveRewardFile")
    @PostMapping("incentiveRewardFile")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:add")
    public FebsResponse addIncentiveRewardFile(@Valid IncentiveRewardFile incentiveRewardFile) throws FebsException {
        try {
            incentiveRewardFile.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveRewardFileService.createIncentiveRewardFile(incentiveRewardFile);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveRewardFile失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveRewardFile
     * @author wanghjw
     * @date 2024-09-03 14:08:33
     */
    @Log("逻辑删除IncentiveRewardFile")
    @GetMapping("incentiveRewardFile/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:delete")
    public FebsResponse deleteIncentiveRewardFile(@PathVariable("id") String incentiveRewardFileIds) throws FebsException {
        try {
            IncentiveRewardFile incentiveRewardFile = new IncentiveRewardFile();
            incentiveRewardFile.setDeletedBy(getCurrentUser().getUserName());
            incentiveRewardFile.setDeletedTime(new Date());
            incentiveRewardFile.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveRewardFileService.deleteIncentiveRewardFile(incentiveRewardFile,incentiveRewardFileIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardFile失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveRewardFile
    * @author wanghjw
    * @date 2024-09-03 14:08:33
    */
    @Log("物理删除IncentiveRewardFile")
    @GetMapping("incentiveRewardFile/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:delete")
    public FebsResponse physicallyDeleteIncentiveRewardFile(@PathVariable("id") String incentiveRewardFileIds) throws FebsException {
        try {
            this.incentiveRewardFileService.physicallyDeleteIncentiveRewardFile(incentiveRewardFileIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardFile失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveRewardFile
     * @author wanghjw
     * @date 2024-09-03 14:08:33
     */
    @Log("修改IncentiveRewardFile")
    @PostMapping("incentiveRewardFile/update")
    @ResponseBody
    @RequiresPermissions("incentiveRewardFile:edit")
    public FebsResponse updateIncentiveRewardFile(IncentiveRewardFile incentiveRewardFile) throws FebsException {
        try {
            incentiveRewardFile.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveRewardFileService.updateIncentiveRewardFile(incentiveRewardFile);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveRewardFile失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
